import { LoginParams, login } from '@/services/login';
// import { getToken, setToken } from '@/utils/auth';
import { useState } from 'react';

export default function useUserModel() {
  const [loading, setLoading] = useState(false);
  // const [tokenState, setTokenState] = useState(getToken());

  const toLogin = async (params: LoginParams) => {
    setLoading(true);
    return login(params)
      .then((res: any) => {
        console.log('loginRes ==> ', res);
        if (res.success) {
          // setToken(res.data.token);
          // setTokenState(res.data);
          return Promise.resolve(res);
        }
        return Promise.reject('error');
      })
      .finally(() => {
        setLoading(false);
      });
  };
  // tokenState
  return { toLogin, loading };
}
